package com.yaowk.sfp.utils.verification.sms;

import com.libfintech.verification.repository.config.impl.RedisRepositoryConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author 小凯
 **/
@Component
public class RedisRepositoryFactory {

    @Value("${spring.redis.host:}")
    private String redisHost;
    @Value("${spring.redis.password:}")
    private String redisPassword;

    private static RedisRepositoryConfig redisRepositoryConfig;

    @PostConstruct
    public void init() {
        if (StringUtils.isNotBlank(redisHost)) {
            redisRepositoryConfig = new RedisRepositoryConfig();
            redisRepositoryConfig.setHost(redisHost);
            if (StringUtils.isNotBlank(redisPassword)) {
                redisRepositoryConfig.setPass(redisPassword);
            }
        }
    }

    public static RedisRepositoryConfig getRedisRepositoryConfig() {
        return redisRepositoryConfig;
    }
}
